package com.learn.shop.controller;

import com.learn.shop.constant.R;
import com.learn.shop.pojo.vo.CrawlingNovelVo;
import com.learn.shop.service.CrawlingNovelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

@Api(tags = "抓取小说章节内容")
@RestController
@RequestMapping("crawling")
public class CrawlingNovelController {

    @Autowired
    @Qualifier("CrawlingNovelImplV3")
    private CrawlingNovelService crawlingNovelService;

    /*   @GetMapping("/novel")
       @ApiOperation("解析html")
       public R crawlingNovel(@ApiParam("小说地址url") @RequestParam("url") String url,
                              @ApiParam("小说名") @RequestParam("novelName") String novelName,
                              @ApiParam("域名指定切割位置") @RequestParam("urlSplit") String urlSplit) throws IOException {
           String novel = crawlingNovelService.novel(url, novelName, urlSplit);
           return R.ok(novel);
       }*/
    @PostMapping("/novel")
    @ApiOperation("解析html")
    public R crawlingNovel(@RequestBody CrawlingNovelVo crawlingNovelVo) throws IOException {
        if (crawlingNovelVo != null) {
            String novel = crawlingNovelService.novel(crawlingNovelVo);
            return R.ok(novel);
        } else {
            return R.fail("请确保解析的小说信息填写完整");
        }
    }

}
